<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <link rel="icon" href="*{/images/favicon.ico}" type="image/x-icon" />
  <meta http-equiv="P3P" content="CP='NOI NID'">
  <meta http-equiv="_broadcast_from_" Content="1" />
  <script type="text/javascript" src="*{/js/jquery.js}"></script>
  <script type="text/javascript" src="*{/js/func.js}"></script>
  <script type="text/javascript" src="*{/js/base64.js}"></script>
  <title id="page_title">代码管理</title>
  <link rel="stylesheet" type="text/css" href="*{/style/popup.css}">
  <link rel="stylesheet" type="text/css" href="*{/assets/ztree/css/zTreeStyle.css}">
  
  <link rel="stylesheet" type="text/css" href="*{/assets/cm/css/codemirror.css}">
  <link rel="stylesheet" type="text/css" href="*{/assets/cm/addon/fold/foldgutter.css}" />
  <link rel="stylesheet" type="text/css" href="*{/assets/cm/css/docs.css}">
  <link rel="stylesheet" type="text/css" href="*{/assets/cm/addon/search/matchesonscrollbar.css}">
  <link rel="stylesheet" type="text/css" href="*{/assets/cm/addon/dialog/dialog.css}">
  <link rel="stylesheet" type="text/css" href="*{/assets/cm/css/theme/eclipse.css}">
  <link rel="stylesheet" type="text/css" href="*{/assets/cm/addon/display/fullscreen.css}">
  
  <script type="text/javascript" src="*{/js/md5.js}"></script>
  <script type="text/javascript" src="*{/js/jquery.animate-colors-min.js}"></script>
  <script type="text/javascript" src="*{/js/popup_layer.js}"></script>
  <script type="text/javascript" src="*{/assets/ztree/js/jquery.ztree.core-3.5.js}"></script>
  <script type="text/javascript" src="*{/assets/ztree/js/jquery.ztree.excheck-3.5.js}"></script>
  <script type="text/javascript" src="*{/assets/ztree/js/jquery.ztree.exedit-3.5.js}"></script>
  
  <script type="text/javascript" src="*{/assets/cm/js/codemirror.js}"></script>
  <script type="text/javascript" src="*{/assets/cm/addon/display/fullscreen.js}"></script>
  <script type="text/javascript" src="*{/assets/cm/addon/dialog/dialog.js}"></script>
  <script type="text/javascript" src="*{/assets/cm/addon/scroll/annotatescrollbar.js}"></script>
  <script type="text/javascript" src="*{/assets/cm/addon/search/search.js}"></script>
  <script type="text/javascript" src="*{/assets/cm/addon/search/searchcursor.js}"></script>
  <script type="text/javascript" src="*{/assets/cm/addon/search/matchesonscrollbar.js}"></script>
  <script type="text/javascript" src="*{/assets/cm/addon/edit/matchbrackets.js}"></script>
  <script type="text/javascript" src="*{/assets/cm/addon/hint/show-hint.js}"></script>
  <script type="text/javascript" src="*{/assets/cm/addon/fold/foldcode.js}"></script>
  <script type="text/javascript" src="*{/assets/cm/addon/fold/foldgutter.js}"></script>
  <script type="text/javascript" src="*{/assets/cm/addon/fold/brace-fold.js}"></script>
  <script type="text/javascript" src="*{/assets/cm/addon/fold/indent-fold.js}"></script>
  <script type="text/javascript" src="*{/assets/cm/addon/fold/comment-fold.js}"></script>
  <script type="text/javascript" src="*{/assets/cm/addon/fold/region-fold.js}"></script>
  <script type="text/javascript" src="*{/assets/cm/js/mode/clike.js}"></script>
  <style type="text/css">
      html, body { padding:0px; margin:0px; overflow:auto;font-size:12px;}
      h1 { font-family: 'Overlock SC', cursive; margin:0 auto; }
      h2 { font-family: 'Overlock SC', cursive; margin:10px 0px 0px 0px; padding:0px; }
      .buttons { list-style-type:none; list-style-position:outside; margin:0px; padding:0px; clear:both; }
      .buttons li { float:left }
      .buttons label { font-size:12px;  line-height:20px;  }
      .buttons input { }
      p { font-size:12px; }
      p .keywords {color:#800;}
      .float-menu-area a {text-decoration:none;font-size:14px;color:black;}
      .float-menu-area a:hover{color:red;}
      .float-menu-area a:active{color:yellow;}
      .float-menu-area,.float-menu-open{background:#fbfbfb;border:2px solid #e1e1e1;border-left:0 none;border-top-right-radius:4px;border-bottom-right-radius:4px;box-shadow:1px 1px 2px rgba(0, 0, 0, 0.5);display:inline-block;font-size:16px;}
      .float-menu-area{height:380px;left:0px;padding:10px 15px;;z-index:100;}
      .float-menu-open{height:24px;left:-70px;padding:4px 4px 4px 6px;width:24px;z-index:99;}
      .float-menu-area,.float-menu-open{position:fixed;*zoom:1;_position:absolute;_top:expression(eval(document.documentElement.scrollTop));}
      .float-menu-close{background:url(*{/images/nav-close.png}) no-repeat left top;overflow:hidden;height:24px;opacity:.6;filter:alpha(opacity=60);position:absolute;right:9px;text-indent:100%;top:10px;white-space:nowrap;width:24px;z-index:1000}
      .open-btn{background:url(*{/images/nav-open.png}) no-repeat left top;display:block;overflow:hidden;height:48px;opacity:.6;filter:alpha(opacity=60);text-indent:100%;white-space:nowrap;width:48px;}
      .float-menu-close:hover,.open-btn:hover{opacity:1;filter:alpha(opacity=100);}
                                        
      .abutton,.abutton:visited{
        text-decoration:none;
        border:solid 1px #a6a6a6;
        color:#000000;
        background:-webkit-linear-gradient(top, #f6f6f6, #dddddd);
        padding-top:3px;
        padding-bottom:3px;
        padding-left:5px;
        padding-right:5px;
        text-align:center;
        font-size:12px;
      }
      .abutton:hover {
        color:#ffff00;
      }
      a { text-decoration:none;}
      .select_ele {
        line-height:22px;
        cursor:pointer;
      }
      .select_ele:hover {
        color:red;
      }
    .mouse_hover:hover {
      cursor:pointer;
    color:red;
    }
    .CodeMirror-code,.CodeMirror-line {
      font-family:"courier new" !important;
    }
  </style>
</head>
<body>
<div id="code_help_area" class="blk" style="display:none;">
    <div class="head"><div class="head-right"></div></div>
    <div class="main" id="main_area">
        <h2 id="title_area"></h2>
        <a href="javascript:void(0)" id="close_popup_bt2" class="closeBtn">关闭</a>
        <div id="main_list" style="width:400px;font-size:13px;height:200px;overflow:auto;"></div>
    </div>
    <div class="foot"><div class="foot-right"></div></div>
</div>
<div id="source_popup_area" class="blk" style="display:none;">
    <div class="head"><div class="head-right"></div></div>
    <div class="main">
        <h2>编译结果</h2>
        <p><textarea id="build_source_area" style="margin-left:15px;width:460px;height:180px;margin-bottom:5px;"></textarea></p>
    <a href="javascript:void(0)" id="source_popup_bt" class="closeBtn">关闭</a>
    </div>
    <div class="foot"><div class="foot-right"></div></div>
</div>
<div id="select_script_area" class="blk" style="display:none;">
    <div class="head"><div class="head-right"></div></div>
    <div class="main">
        <h2>选择多个脚本</h2>
        <div id="script_id_area" style="height:200px;overflow:auto;margin-top:10px;padding-left:10px;"></div>
    <a href="javascript:void(0)" id="select_script_bt" class="closeBtn">关闭</a>
    </div>
    <div class="foot"><div class="foot-right"></div></div>
</div>
<div id="script_io_area" class="blk" style="display:none;">
    <div class="head"><div class="head-right"></div></div>
    <div class="main" id="main_area">
        <h2 id="title_area"></h2>
        <a href="javascript:void(0)" id="close_popup_bt5" class="closeBtn" style="width:80px;">关闭</a>
    <a href="javascript:void(0)" id="close_popup_bt6" style="position:absolute;top:80px;right:10px;display:block;width:80px;padding:4px 0;text-align:center;background:#fff;border:1px solid #85B6E2;color:red;font-size:8px;" onclick="javascript:afterImpScriptClick(true);">带主键导入</a>
        <a href="javascript:void(0)" id="close_popup_bt7" style="position:absolute;top:120px;right:10px;display:block;width:80px;padding:4px 0;text-align:center;background:#fff;border:1px solid #85B6E2;color:#333;font-size:8px;" onclick="javascript:afterImpScriptClick();">无主键导入</a>
          <div id="script_main_list" style="width:400px;font-size:13px;height:200px;overflow:auto;">
      <textarea id="script_content" style="width:400px;height:200px;"></textarea>
    </div>
    </div>
    <div class="foot"><div class="foot-right"></div></div>
</div>
<div id="field_io_area" class="blk" style="display:none;">
    <div class="head"><div class="head-right"></div></div>
    <div class="main" id="main_area">
        <h2 id="title_area"></h2>
        <a href="javascript:void(0)" id="close_popup_bt3" class="closeBtn">关闭</a>
    <a href="javascript:void(0)" id="close_popup_bt4" style="position:absolute;top:50px;right:10px;display:block;width:60px;padding:4px 0;text-align:center;background:#fff;border:1px solid #85B6E2;color:#333;" onclick="javascript:afterImpFieldClick();">确定</a>
        <div id="main_list" style="width:400px;font-size:13px;height:200px;overflow:auto;">
      <textarea id="field_content" style="width:400px;height:200px;"></textarea>
    </div>
    </div>
    <div class="foot"><div class="foot-right"></div></div>
</div>
<div class="main_div">
    <div class="float-menu-open" id="float-menu-open" menu="float-menu-area" style="left:-2px;top:106px;"><a class="open-btn" href="javascript:void(0);" title="脚本"></a></div>
    <div class="float-menu-open" id="float-menu-open2" menu="float-menu-area2" style="left:-2px;top:146px;"><a class="open-btn" href="javascript:void(0);" title="操作"></a></div>
    <div class="float-menu-area" id="float-menu-area" width="800" menu="float-menu-open" style="left:-900px;top:106px;width:800px;height:420px;overflow:auto;">
        <a class="float-menu-close" href="javascript:void(0);">X</a>
        <div class="left_div">
          <div style="width:100%;height:100px;position:relative;">
              <div id="path_explain" style="font-size:13px;margin-top:5px;margin-left:5px;"></div>
              <input type="hidden" id="path_aname"/>
          	  <input type="hidden" id="path_atype"/>
              <input type="hidden" id="path_footer"/>
              <input type="text" disabled  style="width:400px;" id="show_sub_path"/>
              <div style="height:20px;text-align:right;position:absolute;left:0px;bottom:8px;right:5px;">
          		<input type="button" value="搜索" class="path_popup_btn" onclick="javascript:popSearch();" title="支持脚本主键模糊搜索（支持中间带*或空格通配符），也支持脚本标题模糊搜索"/>
                  <a href="*{/editor/search.htm}" target="_blank" class="abutton" style="font-size:12px;">高级搜索</a>
                  <input type="button" value="刷新树" class="path_popup_btn" onclick="javascript:reloadTree();"/>
          		<input type="button" value="编译" class="compile_btn" onclick="javascript:buildPath();"/>
                  &nbsp;&nbsp;
                  <input type="button" value="修改路径" class="path_popup_btn" onclick="javascript:showEditPath(true);"/>
                  <input type="button" value="新增路径" class="path_popup_btn" onclick="javascript:showEditPath();"/>
                  &nbsp;&nbsp;
                  <input type="button" value="新增脚本" onclick="javascript:addNewScript();" />
              </div>
          </div>
          <div style="width:100%;vertical-align:top;margin-top:5px;margin-left:3px;"><ul id="tree_area" class="ztree"></ul></div>
          <div id="path_popup_area" class="blk" style="display:none;">
              <div class="head"><div class="head-right"></div></div>
              <div class="main">
                  <h2>编辑路径信息</h2>
                  <div style="margin-top:5px; margin-bottom:5px;margin-left:15px;font-size:13px;">
                    <span title="脚本前缀，通常都是大写字母，尽量短小精炼，前缀用来说明脚本用途，比如测试，服务，动作，字典等等">类型（脚本前缀）：</span>
                    <input type="text" id="type_val" style="width:50px;" title="只允许大写字母，通常不超过4个字母"/>
                    <select id="type_select" title="常用前缀" ><option value="">无</option></select>
                  </div>
                  <div style="margin-top:5px; margin-bottom:5px;margin-left:15px;font-size:13px;">
                    <span title="该分类中，脚本的后缀，用来说明脚本专用用途，比如某个模块">脚本后缀：</span>
                    <input type="text" id="footer_val" style="width:100px;" title="只允许大写字母，通常不超过4个字母"/>
                  </div>
                  <a href="javascript:void(0)" id="save_popup_bt" class="saveBtn">保存</a>
                  <a href="javascript:void(0)" id="close_popup_bt" class="closeBtn">关闭</a>
                  <p>
                      <input type="text" id="edit_path_name" placeholder="分类名称" style="width:460px;margin-left:15px;" />
                      <input type="hidden" id="edit_path_subpath" />
                      <input type="hidden" id="edit_mode" />
                  </p>
                  <p><textarea id="edit_path_explain" placeholder="分类说明" style="margin-left:15px;width:460px;height:180px;margin-bottom:5px;"></textarea></p>
              </div>
              <div class="foot"><div class="foot-right"></div></div>
          </div>
        </div>
    </div>
    <div class="float-menu-area" id="float-menu-area2" width="200" menu="float-menu-open2" style="left:-300px;top:146px;width:200px;height:320px;">
        <a class="float-menu-close" href="javascript:void(0);">X</a>
        <div style="width:100%;font-size:14px;padding-top:30px;">
            <div style="margin-top:20px;">
                <a href="#" onclick="javascript:saveScript();return false;">保存当前脚本</a>
            </div>
            <div style="margin-top:20px;">
                <a href="#" onclick="javascript:deleteScript();return false;">删除当前脚本</a>
            </div>
            <div style="margin-top:20px;">
                <a href="#" onclick="javascript:rebuildScript();return false;">重新编译全部脚本</a>
            </div>
            <div style="margin-top:20px;">
                <a href="#" onclick="javascript:moveScript();return false;">当前脚本移动到</a>
            </div>
            <div style="margin-top:20px;">
                <a href="*{/N100030.ha}&id=" onclick="javascript:return downloadScript(this);" target="_blank">下载当前脚本备份</a>
            </div>
            <div style="margin-top:20px;">
                <a href="*{/N100029.ha}" onclick="javascript:ml_close_menu();" target="_blank">备份全部脚本</a>
            </div>
            <div style="margin-top:20px;">
                <a href="#" onclick="javascript:refreshScript();" >刷新当前脚本</a>
            </div>
        </div>
    </div>
    <div class="right_div" style="z-index:50;">
        <div id="flash-loader"></div>
        <div id="source_info"></div>
    </div>
    <div class="clear"></div>
</div>
<script type="text/javascript" defer>
reloadTree(); //加载菜单
var lastContent = null; //上一次代码

var lineWarp = false;
var editor; //编辑器
function createEditor(){
  $("#content").val(fixResContent($("#content").val()));
  editor = CodeMirror.fromTextArea($("#content")[0], {
      lineNumbers: true,
      lineWrapping : lineWarp,
      matchBrackets:true,//括号匹配
      showCursorWhenSelecting: true,
      theme: "eclipse",
      foldGutter: true,
      gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"],
      extraKeys: {
        "F11": function(cm) {
          cm.setOption("fullScreen", !cm.getOption("fullScreen"));
        },
        "Esc": function(cm) {
          if (cm.getOption("fullScreen")) cm.setOption("fullScreen", false);
        },
        "Ctrl-S": function(cm){
          saveScript();
        },
        "Ctrl-I": function(cm){
          lineWarp = !lineWarp;
          cm.setOption("lineWrapping",lineWarp);
        },
                "Shift-Ctrl-S" : function(cm){
                  saveScript(false,true);
                },
        "Ctrl-U": function(cm){
          var str = cm.getSelection();
          try{
            cm.replaceSelection(str.toUpperCase());
          }catch(e){
            cm.replaceSelection(str);
          }
        },
        "Ctrl-L": function(cm){
          var str = cm.getSelection();
          try{
            cm.replaceSelection(str.toLowerCase());
          }catch(e){
            cm.replaceSelection(str);
          }
        }
      },
      matchBrackets: true,
      mode : "text/x-java"
    });
  $(".CodeMirror").height(700);
  editor.refresh();
  editor.on("change",function(){
    codeHasChange = true;
  });
}

var codeHasChange = false;

window.setInterval(doAutoSave,5*60*1000);

function doAutoSave(){
  if(!codeHasChange){
    return;
  }
  codeHasChange = false;
  var content = editor.getValue();
  if(content==""){
    return;
  }
  var id = $("#source_info").find("#id").val();
  if(id==""){
    id = "_blank_";
  }
  ldata("auto_save_"+id,content);
  console.log("自动保存代码到浏览器缓存中");
}

function reloadAutoSave(){
  var id = $("#source_info").find("#id").val();
  if(id==""){
    id = "_blank_";
  }
  var content = ldata("auto_save_"+id,null,true);
  if(!content || content==""){
    alert("没有获取到代码");
    return;
  }
  editor.setValue(content);
}

//还原上一次代码
function returnLastContent(){
  if(editor && lastContent){
    editor.setValue(lastContent);
  }
}

function saveScript(showSource,saveMsg){
  var changeMessage;
  if(saveMsg){
    changeMessage = prompt("本次修改原因：","");
  }else{
    changeMessage = "";
  }
  var info = $("#source_info");
  if(!info.find("#sub_path").val()){
    alert("请选择脚本");
    ml_close_menu();
    return;
  }
  var xml = getXmlFromPage(info,changeMessage);
  if(xml==""){
    return;
  }
  lastContent = editor.getValue();
  
  if(showSource){
    $("#source_form").find("#xml_string").val(Base64.e64(xml));
    $("#source_form")[0].submit();
    return;
  }
  xml = queryXml("*{/N100018.ha}",xml,true); //调用提交方法
  
  var noSingleCompile = getChexkBoxVal(info.find("#no_single_compile"));
  if(noSingleCompile){
    $("#no_single_compile").prop("checked",false);
  }
  
  var errorMsg = xml.find("error_msg").text();
    
  var sVer = xml.find("ver").text()
  if(!sVer){
    if(!errorMsg){
      errorMsg = "提交失败，没有获取到脚本的版本号，或请检查网络\n\n"+xml.xml;
    }
  }
  info.find("#error_msg").val(errorMsg);
  if(errorMsg && errorMsg!=""){
    $("body").animate({"backgroundColor":"#ffff00"},100,null,function(){
      $("body").animate({"backgroundColor":"#ffbcbc"},200);
    });
    return;
  }else{
  
    //清空自动保存的代码
    var autoId = $("#source_info").find("#id").val();
    if(autoId==""){
      autoId = "_blank_";
    }
    ldata("auto_save_"+autoId,null,true);
    
    $("body").animate({"backgroundColor":"#ffff00"},100,null,function(){
      $("body").animate({"backgroundColor":"#c8ffc5"},200);
    });
  }
  info.find("#source_file_ver").val(sVer);
  info.find("#file_sn").val(xml.find("file_sn").text());
  info.find("#class_file_ver").val(xml.find("class_ver").text());
  scriptId = xml.find("id").text();
  subPath = xml.find("sub_path").text()
  info.find("#id").val(scriptId);
  $("#page_title").text(scriptId+" "+info.find("#title").val());
  info.find("#sub_path").val(subPath);
 
  setPageFromXml(xml,info); //设置xml数据到页面
  
  //重新加载
  reloadTree(subPath+"/"+scriptId+".xml");
  ml_close_menu();
}

function importScript(){
    ml_close_menu();
  var area = $("#script_io_area");
    area.find("#title_area").text("导入整个脚本");
  area.find("#close_popup_bt6").show();
    area.find("#close_popup_bt7").show();
  area.find("#io_type").val("1");
  area.find("#script_content").val("");
    new PopupLayer({popupBlk:"#script_io_area",closeBtn:"#close_popup_bt5"});
    area.find("#script_content").focus();
}

function exportScript(){
    ml_close_menu();
  var area = $("#script_io_area");
  
    area.find("#title_area").text("导出整个脚本");
  area.find("#close_popup_bt6").hide();
    area.find("#close_popup_bt7").hide();
  area.find("#script_content").val(getXmlFromPage());
    new PopupLayer({popupBlk:"#script_io_area",closeBtn:"#close_popup_bt5"});
    area.find("#script_content").focus();
}


function afterImpScriptClick(needId){
  var area = $("#script_io_area");
  if(area.find("#io_type").val()=="0"){
    ml_close_menu();
    return;
  }
  var content = area.find("#script_content").val();
  setPageFromXml($($.parseXML(content)),null,needId); //设置xml数据到页面
  $("#is_imported").val("1"); //标记内容是导入过来的
  independentClassClick();
  $("#close_popup_bt5").click();
}

/**
 * 从页面获取值拼装为xml字符串
 */
function getXmlFromPage(info,changeMessage){
  if(!info){
    info = $("#source_info");
  }
  var xml = "<?xml version=\"1.0\" encoding='UTF-8'?>\n";
  var subPath = info.find("#sub_path").val(); //文件路径，左侧树节点主键
  var scriptId = info.find("#id").val(); //脚本主键
  var value;
  xml += "<root>\n";

  var noSingleCompile = getChexkBoxVal(info.find("#no_single_compile"));
  if(noSingleCompile){
      xml += "\t<no_single_compile>1</no_single_compile>\n";
  }

  value = getChexkBoxVal(info.find("#independent_class"));
  if(value){
      xml += "\t<independent_class>1</independent_class>\n";
  }
  xml += "\t<cluster_group>"+info.find("#cluster_group").val()+"</cluster_group>\n";
  xml += "\t<file_sn>"+info.find("#file_sn").val()+"</file_sn>\n";
  xml += "\t<create_time>"+info.find("#create_time").val()+"</create_time>\n";
  xml += "\t<id>"+scriptId+"</id>\n";
  xml += "\t<header>"+info.find("#header").val()+"</header>\n";
  xml += "\t<footer>"+info.find("#footer").val()+"</footer>\n";
  xml += "\t<sub_path>"+subPath+"</sub_path>\n";

  value = info.find("#title").val();
  if(!value){
    alert("别忘了输入脚本标题，麻溜的");
    return "";
  }
  xml += "\t<title>"+value+"</title>\n";
  xml += "\t<explain><![CDATA["+info.find("#explain").val()+"]]></explain>\n";
  xml += "\t<ver>"+info.find("#source_file_ver").val()+"</ver>\n";
  xml += "\t<import_content_md5>"+info.find("#import_content_md5").val()+"</import_content_md5>\n";

  value = info.find("#script_build_id").val();
  if(value){
      xml += "\t<script_build_id>"+value+"</script_build_id>\n";
  }

  value = info.find("#interface_classpath").val();
  if(value){
      xml += "\t<interface_classpath>"+value+"</interface_classpath>\n";
  }
  value = info.find("#ext_lib_paths").val();
  if(value){
      xml += "\t<ext_lib_paths>"+value+"</ext_lib_paths>\n";
  }
  value = info.find("#after_start_method").val();
  if(value){
      xml += "\t<after_start_method>"+value+"</after_start_method>\n";
  }
  value = info.find("#destory_method").val();
  if(value){
      xml += "\t<destory_method>"+value+"</destory_method>\n";
  }
  value = info.find("#init_method").val();
  if(value){
      xml += "\t<init_method>"+value+"</init_method>\n";
  }
  value = getChexkBoxVal(info.find("#is_shadow"));
  if(value){
      xml += "\t<is_shadow>"+value+"</is_shadow>\n";
  }
  value = getChexkBoxVal(info.find("#is_db_transaction"));
  if(value){
      xml += "\t<is_db_transaction>"+value+"</is_db_transaction>\n";
  }
  value = getChexkBoxVal(info.find("#is_class_var"));
  if(value){
      xml += "\t<is_class_var>"+value+"</is_class_var>\n";
  }
  value = getChexkBoxVal(info.find("#no_out_log"));
  if(value){
      xml += "\t<no_out_log>"+value+"</no_out_log>\n";
  }
  value = getChexkBoxVal(info.find("#is_sync"));
  if(value){
      xml += "\t<is_sync>"+value+"</is_sync>\n";
  }
  value = getChexkBoxVal(info.find("#action_special_code"));
  if(value){
      xml += "\t<action_special_code>"+value+"</action_special_code>\n";
  }
  value = info.find("#register_id").val();
  if(value){
      xml += "\t<register_id>"+value+"</register_id>\n";
  }
  value = getChexkBoxVal(info.find("#disabled"));
  if(value){
      xml += "\t<disabled>"+value+"</disabled>\n";
  }
  value = getChexkBoxVal(info.find("#enabled_action_charge"));
  if(value){
      xml += "\t<enabled_action_charge>"+value+"</enabled_action_charge>\n";
  }
  value = getChexkBoxVal(info.find("#is_parent"));
  if(value){
      xml += "\t<is_parent>"+value+"</is_parent>\n";
  }
  value = getChexkBoxVal(info.find("#is_static"));
  if(value){
      xml += "\t<is_static>"+value+"</is_static>\n";
  }
  value = info.find("#singleton_level").val();
  if(value){
      xml += "\t<singleton_level>"+value+"</singleton_level>\n";
  }
  value = info.find("#parent_bean_id").val();
  if(value){
      xml += "\t<parent_bean_id>"+value+"</parent_bean_id>\n";
  }
  value = getChexkBoxVal(info.find("#cluster_master_task_run"));
  if(value){
      xml += "\t<cluster_master_task_run>"+value+"</cluster_master_task_run>\n";
  }
  value = getChexkBoxVal(info.find("#cluster_call_only"));
  if(value){
      xml += "\t<cluster_call_only>"+value+"</cluster_call_only>\n";
  }
  var divs = info.find("#in_fields").find(".tr");
  if(divs && divs.length>0){
      if($("#in_field_list")[0].checked){
          xml += "\t<in list=\"true\">\n";
      }else{
          xml += "\t<in>\n";
      }
      var inVarName;
      for(var i=0;i<divs.length;i++){
        inVarName = $(divs[i]).find("#name").val();
        if(!inVarName){
          continue;
        }
          xml += "\t\t<field>\n";
          xml += "\t\t\t<name>"+inVarName+"</name>\n";
          xml += "\t\t\t<type>"+$(divs[i]).find("#type").val()+"</type>\n";
          value = getChexkBoxVal($(divs[i]).find("#not_null"));
          if(value){
              xml += "\t\t\t<not_null>"+value+"</not_null>";
          }
          xml += "\t\t\t<default_value>"+$(divs[i]).find("#default_value").val()+"</default_value>\n";
          value = getChexkBoxVal($(divs[i]).find("#base64_deccode"));
          if(value){
              xml += "\t\t\t<base64_deccode>"+value+"</base64_deccode>";
          }
          value = $(divs[i]).find("#explain").val();
          if(value){
              xml += "\t\t\t<explain><![CDATA["+value+"]]></explain>\n";
          }
          xml += "\t\t</field>\n";
      }
      xml += "\t</in>\n";
  }
  value = info.find("#out_type").val();
  var value2 = info.find("#out_explain").val();
  if(value || value2){
      xml += "\t<out>\n";
      if(value){
          xml += "\t\t<type>"+value+"</type>\n";
      }
      if(value2){
          xml += "\t\t<explain><![CDATA["+value2+"]]></explain>\n";
      }
      xml += "\t</out>\n";
  }
  
  if(changeMessage && changeMessage!=""){
    xml += "\t<modify_content><![CDATA["+changeMessage+"]]></modify_content>\n";
  }
  
  xml += "\t<content><![CDATA[\n";
  if(editor){
    xml += swap(editor.getValue(),"<![CDATA[","<!^^CDATA[","]]>","]^^>");
  }
  xml += "\n]]></content>\n";
  xml += "</root>";
  return xml;
}

/**
 * 设置xml数据到页面
 */
function setPageFromXml(xml,info,needId){
  if(!xml){
     return; 
  }
  if(!info){
    info = $("#source_info");
  }
  var root = xml.find("root");
  
  var divs = root.children("title");
  if(divs && divs.length>0){
    info.find("#title").val($(divs[0]).text());
  }
  var divs = root.children("header");
  if(divs && divs.length>0){
    info.find("#header").val($(divs[0]).text());
  }
  var divs = root.children("footer");
  if(divs && divs.length>0){
    info.find("#footer").val($(divs[0]).text());
  }
  divs = root.children("explain");
  if(divs && divs.length>0){
    info.find("#explain").val($(divs[0]).text());
  }
  divs = root.children("create_time");
  if(divs && divs.length>0){
    info.find("#create_time").val($(divs[0]).text());
  }
  var localId = str(info.find("#id").val());
  var srcId   = "";
  divs = root.children("id");
  if(divs && divs.length>0){
    srcId = $(divs[0]).text();
  }
  
  divs = root.children("content");
  if(divs && divs.length>0){
    var cnt     = $(divs[0]).text();
    var content = fixResContent(cnt);

    info.find("#content").val(content);
    editor.getDoc().setValue(content);
    
    //不改变版本号的条件：来源脚本主键与当前脚本主键相同。脚本内容导入后没有发生变化
    divs = root.children("ver");
    if(divs && divs.length>0 && localId==srcId && localId!=""){
      info.find("#import_content_md5").val(hex_md5(cnt));
      info.find("#source_file_ver").val($(divs[0]).text());
    }
  }
  if(needId && localId==""){
    info.find("#id").val(srcId);
  }
  info.find("#after_start_method").val(xml.find("after_start_method").text());
  info.find("#destory_method").val(xml.find("destory_method").text());
  info.find("#init_method").val(xml.find("init_method").text());
  value = xml.find("is_shadow").text().toLowerCase();
  if(value=="1" || value=="true"){
    info.find("#is_shadow")[0].checked = true;
  }
  value = xml.find("independent_class").text().toLowerCase();
  if(value=="1" || value=="true"){
    info.find("#independent_class")[0].checked = true;
  }
  value = xml.find("is_db_transaction").text().toLowerCase();
  if(value=="1" || value=="true"){
    info.find("#is_db_transaction")[0].checked = true;
  }
  value = xml.find("is_class_var").text().toLowerCase();
  if(value=="1" || value=="true"){
    info.find("#is_class_var")[0].checked = true;
  }
  value = xml.find("no_out_log").text().toLowerCase();
  if(value=="1" || value=="true"){
    info.find("#no_out_log")[0].checked = true;
  }
  value = xml.find("is_sync").text().toLowerCase();
  if(value=="1" || value=="true"){
    info.find("#is_sync")[0].checked = true;
  }
  value = xml.find("is_parent").text().toLowerCase();
  if(value=="1" || value=="true"){
    info.find("#is_parent")[0].checked = true;
  }
  value = xml.find("action_special_code").text().toLowerCase();
  if(value=="1" || value=="true"){
    info.find("#action_special_code")[0].checked = true;
  }
  info.find("#register_id").val(xml.find("register_id").text());
    
  value = xml.find("disabled").text().toLowerCase();
  if(value=="1" || value=="true"){
    info.find("#disabled")[0].checked = true;
  }

  value = xml.find("enabled_action_charge").text().toLowerCase();
  if(value=="1" || value=="true"){
    info.find("#enabled_action_charge")[0].checked = true;
  }
  
  value = xml.find("is_static").text().toLowerCase();
  if(value=="1" || value=="true"){
    info.find("#is_static")[0].checked = true;
  }
  
  value = xml.find("cluster_master_task_run").text().toLowerCase();
  if(value=="1" || value=="true"){
    info.find("#cluster_master_task_run")[0].checked = true;
  }
  value = xml.find("cluster_call_only").text().toLowerCase();
  if(value=="1" || value=="true"){
    info.find("#cluster_call_only")[0].checked = true;
  }
  
  info.find("#singleton_level").val(xml.find("singleton_level").text());
  info.find("#parent_bean_id").val(xml.find("parent_bean_id").text());
  info.find("#interface_classpath").val(xml.find("interface_classpath").text());
  info.find("#ext_lib_paths").val(xml.find("ext_lib_paths").text());
  info.find("#import_script").html("");
  divs = xml.find("load_script").find("value");
  var subHtml = "";
  if(divs && divs.length>0){
    var scriptDiv;
    for(var i=0;i<divs.length;i++){
      scriptDiv = $(divs[i]);
      subHtml += "<div id=\"tr\" class=\"tr\"><div style=\"float:left;font-weight:bold;text-align:center;width:100px;margin-top:5px;\" >";
      subHtml += scriptDiv.text();
      subHtml += "</div><div style=\"float:left;font-weight:bold;text-align:left;width:300px;margin-top:5px;\">";
      subHtml += scriptDiv.attr("title");
      subHtml += "</div><div style=\"clear:both;\"></div></div>";
    }
    info.find("#import_script").html(subHtml);
  }
  var fieldNode = xml.find("in");
  value = fieldNode.attr("list");
  if(value){
    value = value.toLowerCase();
  }
  if(value=="1" || value=="true"){
    info.find("#in_field_list")[0].checked = true;
  }
  divs = fieldNode.find("field");
  info.find("#in_fields").html("");
  if(divs && divs.length>0){
    subHtml = "";
    var fieldNode;
    for(var i=0;i<divs.length;i++){
      fieldNode = $(divs[i]);
      subHtml += "<div id=\"tr\" class=\"tr\">";
      subHtml += "<div style=\"float:left;font-weight:bold;text-align:left;width:200px;margin-top:5px;\" >";
      subHtml += "<input type=\"text\" id=\"name\" style=\"width:198px;\" value=\""+fieldNode.find("name").text()+"\"/>";
      subHtml += "</div>";
      subHtml += "<div style=\"float:left;font-weight:bold;text-align:left;width:200px;margin-top:5px;\">";
      subHtml += "<input type=\"text\" id=\"type\" style=\"width:135px;margin-left:10px;\" value=\""+fieldNode.find("type").text()+"\"/>";
      subHtml += "<input type=\"button\" value=\"？\" onclick=\"javascript:showHelpInfo('types',$(this.parentNode).find('#type'));\"/>";
      subHtml += "</div>";
      subHtml += "<div style=\"float:left;font-weight:bold;text-align:center;width:70px;margin-top:5px;\">";

      value = fieldNode.find("not_null").text().toLowerCase();
      if(value=="1" || value=="true"){
        subHtml += "<input type=\"checkbox\" id=\"not_null\" value=\"1\" checked />";
      }else{
        subHtml += "<input type=\"checkbox\" id=\"not_null\" value=\"1\" />";
      }
      subHtml += "</div>";
      subHtml += "<div style=\"float:left;font-weight:bold;text-align:left;width:250px;margin-top:5px;\">";
      subHtml += "<input type=\"text\" id=\"explain\" style=\"width:248px;\" value=\""+fieldNode.find("explain").text()+"\"/>";
      subHtml += "</div>";
      subHtml += "<div style=\"float:left;font-weight:bold;text-align:left;width:100px;margin-top:5px;margin-left:10px;\">";
      subHtml += "<input type=\"text\" id=\"default_value\" style=\"width:88px;\" value=\""+fieldNode.find("default_value").text()+"\"/>";
      subHtml += "</div>";
      subHtml += "<div style=\"float:left;font-weight:bold;text-align:center;width:70px;margin-top:5px;\">";
      value = fieldNode.find("base64_deccode").text().toLowerCase();
      if(value=="1" || value=="true"){
        subHtml += "<input type=\"checkbox\" id=\"base64_deccode\" value=\"1\" checked />";
      }else{
         subHtml += "<input type=\"checkbox\" id=\"base64_deccode\" value=\"1\" />";
      }
      subHtml += "</div>";
      subHtml += "<div style=\"float:left;font-weight:bold;text-align:center;width:110px;margin-top:5px;\">";
      subHtml += "<input type=\"button\" value=\"Delete\" onclick=\"javascript:deleteFieldrow(this);\" />";
      subHtml += "<input type=\"button\" value=\"↑\" onclick=\"javascript:moveUp(this);\" />";
      subHtml += "<input type=\"button\" value=\"↓\" onclick=\"javascript:moveDown(this);\" />";
      subHtml += "</div>";
      subHtml += "<div style=\"clear:both;\"></div>";
      subHtml += "</div>";  
    }
    info.find("#in_fields").html(subHtml);
  }
  fieldNode = xml.find("out");
  if(fieldNode && fieldNode.length>0){
    var outInfo = fieldNode.find("type");
    if(outInfo && outInfo.length>0){
      info.find("#out_type").val(outInfo.text());
    }
    outInfo = fieldNode.find("explain");
    if(outInfo && outInfo.length>0){
      info.find("#out_explain").val(outInfo.text());
    }
  }
}

//重新编译全部脚本
function rebuildScript(){
    getUrlValue("*{/N100020.ha}");
    //重新加载
    reloadTree(null);
    ml_close_menu();
}


//移动当前脚本
function moveScript(){
    var info = $("#source_info");
    var id = info.find("#id").val();
    if(!id){
        alert("没有选择指定脚本");
        return;
    }
    var title = info.find("#title").val();
    var subPath = prompt('输入将要迁移脚本【'+title+'('+id+')的路径：',"");
    if(!subPath){
        return;
    }
    getUrlValue("*{/N100028.ha}","id="+id+"&sub_path="+subPath);
    //重新加载
    reloadTree(subPath);
    ml_close_menu();
}

//插入传入参数信息
function addInFieldRow(){
    var subHtml = "<div id=\"tr\" class=\"tr\">";
    subHtml += "<div style=\"float:left;font-weight:bold;text-align:left;width:200px;margin-top:5px;\" >";
    subHtml += "<input type=\"text\" id=\"name\" style=\"width:198px;\"/>";
    subHtml += "</div>";
    subHtml += "<div style=\"float:left;font-weight:bold;text-align:left;width:200px;margin-top:5px;\">";
    subHtml += "<input type=\"text\" id=\"type\" style=\"width:135px;margin-left:10px;\"/>";
    subHtml += "<input type=\"button\" value=\"？\" onclick=\"javascript:showHelpInfo('types',$(this.parentNode).find('#type'));\"/>";
    subHtml += "</div>";
    subHtml += "<div style=\"float:left;font-weight:bold;text-align:center;width:70px;margin-top:5px;\">";
    subHtml += "<input type=\"checkbox\" id=\"not_null\" value=\"1\"/>";
    subHtml += "</div>";
    subHtml += "<div style=\"float:left;font-weight:bold;text-align:left;width:250px;margin-top:5px;\">";
    subHtml += "<input type=\"text\" id=\"explain\" style=\"width:248px;\"/>";
    subHtml += "</div>";
    subHtml += "<div style=\"float:left;font-weight:bold;text-align:left;width:100px;margin-top:5px;margin-left:10px;\">";
    subHtml += "<input type=\"text\" id=\"default_value\" style=\"width:88px;\"/>";
    subHtml += "</div>";
    subHtml += "<div style=\"float:left;font-weight:bold;text-align:center;width:70px;margin-top:5px;\">";
    subHtml += "<input type=\"checkbox\" id=\"base64_deccode\" value=\"1\"/>";
    subHtml += "</div>";
    subHtml += "<div style=\"float:left;font-weight:bold;text-align:center;width:110px;margin-top:5px;\">";
    subHtml += "<input type=\"button\" value=\"Delete\" onclick=\"javascript:deleteFieldrow(this);\"/>";
    subHtml += "<input type=\"button\" value=\"↑\" onclick=\"javascript:moveUp(this);\"/>";
    subHtml += "<input type=\"button\" value=\"↓\" onclick=\"javascript:moveDown(this);\"/>";
    subHtml += "</div>";
    subHtml += "<div style=\"clear:both;\"></div>";
    subHtml += "</div>";
    
    $("#in_fields").append(subHtml);
}

function moveUp(node){
  var node = $(node.parentNode.parentNode);
  var up   = node.prev();
  if(up.length>0){
    node.insertBefore(up);
  }
}

function moveDown(node){
  var node = $(node.parentNode.parentNode);
  var down = node.next();
  if(down.length>0){
    node.insertAfter(down);
  }
}

//删除传入参数信息
function deleteFieldrow(node){
    node.parentNode.parentNode.parentNode.removeChild(node.parentNode.parentNode);
}

function deleteScript(){
  var msg = prompt("请输入删除脚本原因：","");
  //执行删除脚本
  getUrlValue("*{/N100021.ha}","id="+$("#source_info").find("#id").val()+"&msg="+msg);
  //重新加载
  reloadTree($("#source_info").find("#sub_path").val());
  ml_close_menu();
  
  //清空自动保存的代码
  var autoId = $("#source_info").find("#id").val();
  if(autoId==""){
    autoId = "_blank_";
  }
  ldata("auto_save_"+autoId,null,true);
}

function refreshScript(){
  ml_close_menu();
  var subPath = $("#source_info").find("#sub_path").val();
  if(!subPath){
    return;
  }
  var scriptId = $("#source_info").find("#id").val();
  if(!scriptId){
    return;
  }
  var json = getJson("*{/N100081.ha}","script_id="+scriptId+"&sub_path="+subPath);
  if(json.status!=1){
    $("#source_info").find("#error_msg").val(json.msg);
  }else{
    $("#source_info").html(getUrlValue("*{/editor/editor.htm}","path=/"+subPath+"/"+scriptId+".xml"));
      $("#content").val(fixResContent($("#content").val()));
    createEditor();
    showForScriptInfo();
      showRouteScriptInfo()
    independentClassClick();
      $("#page_title").text($("#script_main_info").find("#id").val()+" "+$("#title").val());
  }
  return false;
}

var pop_after_return_node;
function showHelpInfo(type,afterNode){
    pop_after_return_node = afterNode;
    var pop = $("#code_help_area");
    var title = "";
    if(type=="parent_bean_id"){
        title = "选择父类";
    }else if(type=="register_ids"){
        title = "选择注册类主键";
    }else if(type=="types"){
        title = "选择基本类型";
    }else if(type=='singleton_level'){
        title = "选择常驻内存等级";
    }else if(type=='scripts'){
        title = "选择脚本";
    }else if(type=="script_head"){
    title = "选择脚本头代码";
  }
    pop.find("title_area").text(title);
    var json = getJson("*{/N100022.ha}","type="+type);
    var rs = json.rs;
    var innerHTML = "<table width=\"100%\">";
    for(var i=0;i<rs.length;i++){
        innerHTML+="<tr><td align=\"right\"><input type=\"radio\" value=\""+rs[i].value+"\" onclick=\"javascript:pop_after_return_node.val(this.value);$('#close_popup_bt2').click();\"/></td>";
        innerHTML+="<td align=\"left\" noWrap title=\""+rs[i].explain+"\" >"+rs[i].title+"</td></tr>";
    }
    innerHTML+="</table>";
    pop.find("#main_list").html(innerHTML);
    new PopupLayer({popupBlk:"#code_help_area",closeBtn:"#close_popup_bt2"});
}

function ml_close_menu() {
    var menus = $('.float-menu-area');
    var menu;
    for(var i=0;i<menus.length;i++){
        menu = $(menus[i]);
        var menuId = menus[i].id;
        menu.animate({
            left: "-"+(parseInt(menu.attr("width"))+100)+"px"
        },300, function(){
            var m = $(this);
            $("#"+m.attr("menu")).delay(50).animate({
                left: '-2px'
            }, 300);
        });
    }
}

function ml_open_menu(evt) {
    ml_close_menu();
    if(!evt){
        evt = window.event;
        evt.target = evt.srcElement;
    }
    var menu = $(evt.target.parentNode).attr("menu");
    $(evt.target.parentNode).animate({
        left: '-70px'
    }, 300, function(){
        $('#'+menu).delay(50).animate({
            left: '0px'
        },300);
    });
}

$('.float-menu-close').click(function(){
    ml_close_menu();
    return false;
});
$('.open-btn').click(function(){
    ml_open_menu();
    return false;
});


function showPathInfo(path){
  var dataJson = getJson("*{/N100005.ha}","path="+path);
  $("#path_explain").html(str(dataJson.explain));
  $("#path_aname").val(str(dataJson.aname));
  $("#path_atype").val(str(dataJson.atype));
  $("#path_footer").val(str(dataJson.footer));
  $("#show_sub_path").val(path);
}
showPathInfo("");

function showEditPath(isEdit){
  //选择脚本头下拉框
  var select = $("#type_select");
  select.on("change",function(){
    $("#type_val").val($(this).val());
  });
  if(!select.attr("set_data")){
    select.attr("set_data","1");
      var json = getJson("*{/N100022.ha}","type=script_head");
      var rs = json.rs;
      var innerHTML = "<option value=''>无或继承上一级</option>";
      for(var i=0;i<rs.length;i++){
          innerHTML+="<option value='"+rs[i].value+"'>["+rs[i].value+"]"+rs[i].title+"</option>";
      }
      select.html(innerHTML);
  }
  $("#footer_val").on("keyup",function(){
    $(this).val(str($(this).val()).toUpperCase());
  });
  ml_close_menu();
  $("#folder_name").val("");
  if(isEdit){
    $("#edit_path_name").val($("#path_aname").val());
    $("#edit_path_explain").val($("#path_explain").html());
    var pathType = $("#path_atype").val();
    var opt = $("#type_select").find("[value='"+pathType+"']");
    if(opt.length<1){
      select.append("<option value='"+pathType+"' selected>["+pathType+"]"+$("#path_aname").val()+"</option>");
    }else{
      opt.attr("selected","selected"); 
    }
    $("#type_val").val(pathType);
    $("#footer_val").val($("#path_footer").val());
    $("#edit_mode").val("1");
  }else{
    $("#edit_path_name").val("");
    $("#edit_path_explain").val("");
    $("#type_select").find("[value='']").attr("selected","selected");
    $("#type_val").val("");
    $("#type_footer").val("");
    $("#edit_mode").val("0");
    select.find("option").removeAttr("selected");
  }
  new PopupLayer();
}


$("#save_popup_bt").click(
    function(event){
        var folderName = $("#folder_name").val();
        if(!$("#edit_mode").val()){
            if(!folderName){
                alert("请输入文件夹名（英文）");
                $("#folder_name").focus();
                return;
            }
        }
        var subPath = $("#edit_path_subpath").val();
        if(folderName){
            subPath = subPath+folderName+"/";
        }
        var aname = $("#edit_path_name").val();
        
        var addFlag = "0";
        if($("#edit_mode").val()=="0"){
            addFlag = "1";
        }
        
        var atype = str($("#type_val").val());
        if(atype!=""){
          if(!/^[a-zA-Z]+$/.test(atype)){
            alert("只能输入字母");
            $("#type_val").focus();
            return;
          }
          atype = atype.toUpperCase();
        }
        var footer = str($("#footer_val").val());
         if(footer!=""){
          if(!/^[a-zA-Z]+$/.test(footer)){
            alert("只能输入字母");
            $("#type_val").focus();
            return;
          }
          footer = footer.toUpperCase();
        }
        var dataJson = getJson("*{/N100006.ha}","add="+addFlag+"&path="+subPath+"&aname="+aname+"&atype="+atype+"&footer="+footer+"&explain="+urlEncodePro($("#edit_path_explain").val()));
        if(dataJson.status<0){
            alert(dataJson.msg);
        }
        //重新加载
        reloadTree();
        $("#close_popup_bt").click();
    }
);

function addNewScript(){
    var subPath = $("#edit_path_subpath").val();
    if(!subPath){
        alert("请选择要新增脚本的路径");
        return;
    }
    var res = getUrlValue("*{/editor/editor.htm}","path="+subPath);
  $("#page_title").text("新增脚本");
    $("#source_info").html(res);
    createEditor();
  independentClassClick();
    ml_close_menu();
  $("body").css("backgroundColor","");
  $("#title_area").click();
}

function setCrontabScript(){
  var cnt = [
     '<!\n'
    ,'/** 设置定时时间 **/\n'
    ,'public String getTimeInfo() {\n'
    ,'   //[秒] 分 时 日 月 周 [年]\n'
    ,'  return "* * * * *";\n'
    ,'}\n'
    ,'\n'
    ,'/** 执行任务 **/\n'
    ,'public void run() throws Exception {\n'
    ,'  //到时间时执行的任务\n'
    ,'\n'
    ,'}\n'
    ,'!>\n'
    ,'run(); //测试调用\n'
  ].join('');
  cnt = cnt.replace(/</g,"<"+"%").replace(/>/g,"%"+">");
  $("#singleton_level").val(1);
  $("#parent_bean_id").val("crontabbeanparent");
  $("#register_id").val("crontab_service");
  $("#content").text(cnt);
  $("#is_class_var")[0].checked = false;
  $("#info_href")[0].click();
  $("#title").focus();
  editor.setValue(cnt);
  editor.refresh();
}


function setServiceScript(){
  $("#singleton_level").val(1);
  $("#parent_bean_id").val("servicebeanparent");
  $("#register_id").val("");
  $("#content").text("");
  $("#is_class_var")[0].checked = false;
  $("#info_href")[0].click();
  $("#title").focus();
  editor.setValue("");
  editor.refresh();
}

function setDictScript(){
  var cnt = [
     '<!\n'
    ,'/**\n'
    ,' * 通过查询数据的字段值获取对应的字典值\n'
    ,' * 使用方法：在查询语句后，增加一个参数\n'
    ,' * new Object[]{<％&(脚本代码1)％>,<％&(脚本代码2)％>}\n'
    ,' * （注意：注释中的百分号用了全角字符，需要换成半角字符使用）\n'                                     
    ,' * @param colDataMap 当前插入的行数据 （完整行数据）\n'
    ,' * @author Programer\n'
    ,' */\n'
    ,'public void data(Map<String,String> colDataMap) {\n'
    ,'  //获取需要转化的字段名序列\n'
    ,'  //List<String> fieldList = (List<String>)threadGet("当前脚本主键");\n'
    ,'}\n'
    ,'!>\n'
  ].join('');
  cnt = cnt.replace(/<!/g,"<"+"%!").replace(/!>/g,"!%"+">");
  $("#singleton_level").val(0);
  $("#parent_bean_id").val("dictbeanparent");
  $("#register_id").val("");
  $("#content").text(cnt);
  $("#info_href")[0].click();
  $("#is_class_var")[0].checked = true;
  editor.setValue(cnt);
  editor.refresh();
  $("#title").focus();
}


//导出传入参数
function fieldOut(){
  ml_close_menu();
  var area = $("#field_io_area");
  area.find("#title_area").text("导出参数信息");
  area.find("#close_popup_bt4").hide();
  var content = "";
  var info = $("#source_info");
  var divs = info.find("#in_fields").find(".tr");
  var checkVal; //勾选框值
  if(divs && divs.length>0){
    for(var i=0;i<divs.length;i++){
      if(content.length>0){
        content += "|||";
      }
      checkVal = getChexkBoxVal($(divs[i]).find("#not_null"));
      if(checkVal==""){
        checkVal = "0";
      }
      content+=$(divs[i]).find("#name").val();
      content+="^^"+$(divs[i]).find("#type").val();
      content+="^^"+checkVal;
      content+="^^"+$(divs[i]).find("#explain").val();
      content+="^^"+$(divs[i]).find("#default_value").val();
      checkVal = getChexkBoxVal($(divs[i]).find("#base64_deccode"));
      if(checkVal==""){
        checkVal = "0";
      }
      content+="^^"+checkVal;
    }
  }
  area.find("#field_content").val(content);
  new PopupLayer({popupBlk:"#field_io_area",closeBtn:"#close_popup_bt3"});
}

//导入传入参数
function fieldIn(){
  ml_close_menu();
  var area = $("#field_io_area");
  area.find("#title_area").text("录入导入参数信息");
  area.find("#close_popup_bt4").show();
  area.find("#io_type").val("1");
  area.find("#field_content").val("");
  new PopupLayer({popupBlk:"#field_io_area",closeBtn:"#close_popup_bt3"});
}

//点击关闭导入导出参数层
function afterImpFieldClick(){
  var area = $("#field_io_area");
  if(area.find("#io_type").val()=="0"){
    return;
  }
  var content = area.find("#field_content").val();
  content = content.split("|||");
  var subHtml;
  var inFieldArea = $("#in_fields");
  var ele;
    inFieldArea.empty();
  for(var i=0;i<content.length;i++){
    ele = content[i].split("^^");
    if(ele.length<4){
      continue;
    }
    subHtml = "<div id=\"tr\" class=\"tr\">";
    subHtml += "<div style=\"float:left;font-weight:bold;text-align:left;width:200px;margin-top:5px;\" >";
    subHtml += "<input type=\"text\" id=\"name\" value=\""+ele[0]+"\" style=\"width:198px;\"/>";
    subHtml += "</div>";
    subHtml += "<div style=\"float:left;font-weight:bold;text-align:left;width:200px;margin-top:5px;\">";
    subHtml += "<input type=\"text\" id=\"type\" value=\""+ele[1]+"\" style=\"width:135px;margin-left:10px;\"/>";
    subHtml += "<input type=\"button\" value=\"？\" onclick=\"javascript:showHelpInfo('types',$(this.parentNode).find('#type'));\"/>";
    subHtml += "</div>";
    subHtml += "<div style=\"float:left;font-weight:bold;text-align:center;width:70px;margin-top:5px;\">";
    subHtml += "<input type=\"checkbox\" id=\"not_null\" "+(ele[2]=="1"?"checked":"")+" value=\"1\"/>";
    subHtml += "</div>";
    subHtml += "<div style=\"float:left;font-weight:bold;text-align:left;width:250px;margin-top:5px;\">";
    subHtml += "<input type=\"text\" id=\"explain\" value=\""+ele[3]+"\" style=\"width:248px;\"/>";
    subHtml += "</div>";
    subHtml += "<div style=\"float:left;font-weight:bold;text-align:left;width:100px;margin-top:5px;margin-left:10px;\">";
    subHtml += "<input type=\"text\" id=\"default_value\" value=\""+(ele.length>4?ele[4]:"")+"\" style=\"width:88px;\"/>";
    subHtml += "</div>";
    subHtml += "<div style=\"float:left;font-weight:bold;text-align:center;width:70px;margin-top:5px;\">";
    subHtml += "<input type=\"checkbox\" id=\"base64_deccode\" "+((ele.length>5 && ele[5]=="1")?"checked":"")+" value=\"1\"/>";
    subHtml += "</div>";
    subHtml += "<div style=\"float:left;font-weight:bold;text-align:center;width:110px;margin-top:5px;\">";
    subHtml += "<input type=\"button\" value=\"Delete\" onclick=\"javascript:deleteFieldrow(this);\"/>";
    subHtml += "<input type=\"button\" value=\"↑\" onclick=\"javascript:moveUp(this);\"/>";
    subHtml += "<input type=\"button\" value=\"↓\" onclick=\"javascript:moveDown(this);\"/>";
    subHtml += "</div>";
    subHtml += "<div style=\"clear:both;\"></div>";
    subHtml += "</div>";
    
    inFieldArea.append(subHtml);
    area.find("#close_popup_bt3").click();
  }
}

//搜索指定脚本
var selectScriptLayer = null;
function popSearch(){
  var scriptId = window.prompt("请输入脚本主键关键字","");
  if(!scriptId){
    return;
  }
  var res   = getJson("*{/N100136.ha}","key="+ue64(scriptId));
  var keys  = null;
  if(res!=null && res.status=="1"){
    keys = Object.keys(res);
  }
  if(keys==null || keys.length==null || keys.length<2){
    window.location.href="*{/editor/index.htm}";
    return;
  }
  if(keys.length==2){
    for(var i=0;i<keys.length;i++){
      if(keys[i]!="status"){
        scriptId = keys[i];
        break;
      }
    }
    window.location.href="*{/editor/index.htm}&id="+scriptId;
    return;
  }
  var area = $("#select_script_area").find("#script_id_area").empty();
  for(var i=0;i<keys.length;i++){
    if(keys[i]=="status"){
      continue;
    }
    area.append(['<div class="select_ele" onclick="javascript:selectScript(\'',keys[i],'\');">(',keys[i],')',res[keys[i]],'</div>'].join(''));
  }
  selectScriptLayer = new PopupLayer({popupBlk:"#select_script_area",closeBtn:"#select_script_bt"});
  ml_close_menu();
  return;
}

function selectScript(scriptId){
  window.location.href="*{/editor/index.htm}&id="+scriptId;
}

//处理准备显示在界面上的代码内容
function fixResContent(cnt){
  if(!cnt){
    return "";
  }
  if(startsWith(cnt,"@b64@")){
    cnt = Base64.d64(cnt);
  }else{
    cnt = swap(cnt,"<!^^CDATA[","<![CDATA[","]^^>","]]>");
  }
  if(startsWith(cnt,"\n")){
    cnt = cnt.substring(1);
  }
  if(endsWith(cnt,"\n")){
    cnt = cnt.substring(0,cnt.length-1);
  }
  return cnt;
}


function reloadTree(subPath){
  var treeSetting = {
    data: {
      simpleData : {
        enable     : true,
        idKey      : "sub_path",
        pIdKey     : "up_path",
        rootPId    : ""
      },
      key : {
        name       : "aname"
      }
    },
    callback: {
      onClick: treeClick
    }
  };
  var data = getJson("*{/N100110.ha}","path="+str(subPath)+"&id="+getRequest("id"));
  //初始化树
  $.fn.zTree.init($("#tree_area"), treeSetting, data);
}

function treeClick(event,treeId,treeNode){
  if(treeNode.is_path){
    showPathInfo(treeNode.sub_path+"/");
    $("#edit_path_subpath").val(treeNode.sub_path+"/");
    $.fn.zTree.getZTreeObj(treeId).expandNode(treeNode);
    return false;
  }
  window.location.href="*{/editor/index.htm}&id="+treeNode.id;
  return false;
}

function showForScriptInfo(){
  _parseOneNode($("#for_import_script"),"script_id="+$("#script_main_info").find("#id").val());
  
  if($("#error_msg").text()){
      $("body").css("backgroundColor","#ffbcbc");
  }
  if($("#disabled").prop("checked")){
     $("body").css("backgroundColor","#cccccc");
  }else if($("#independent_class").prop("checked")){
  $("body").css("backgroundColor","#ff9933");
  }else if($("#is_parent").prop("checked")){
     $("body").css("backgroundColor","#ff6600");
  }else if($("#singleton_level").val()>0){
    $("body").css("backgroundColor","#ffff99");
  }else{
    $("body").css("backgroundColor","");
  }
}
function showRouteScriptInfo(){
  var area = $("#_import_route_script");
   _parseOneNode(area,"script_id="+$("#script_main_info").find("#id").val());
  if(area.find("#outside_script_content").text()==""){
    area.hide();
  }
}

               
function downloadScript(node){
  node = $(node);
  if(!node.attr("set_id")){
    node.attr("set_id","1");
    node.attr("href",node.attr("href")+$("#script_main_info").find("#id").val());
  return true;
  }
  ml_close_menu();
  return true;
}

function independentClassClick(){
  var node = $("#independent_class");
  if(node.prop("checked")){
  $("#script_id_title").text("　　传统类名：");
  $("#id").prop("disabled",false);
  $("#script_head_area").hide();
  $("#script_footer_area").hide();
  $("#script_more_info_area").hide();
  }else{
  $("#script_id_title").text("　　脚本代码：");
  $("#id").prop("disabled",true);
  $("#script_head_area").show();
  $("#script_footer_area").show();
  $("#script_more_info_area").show();
  }
}

function buildPath(){
  var subPath = $("#edit_path_subpath").val();
  if(!subPath){
    alert("请选择要新增脚本的路径");
    return;
  }
  $("#build_source_area").text(getUrlValue("*{/N100095.ha}","path="+subPath));
  ml_close_menu();
  new PopupLayer({popupBlk:"#source_popup_area",closeBtn:"#source_popup_bt"});
}

function getCallUrl(){
  var url = window.location.href;
  var point = url.lastIndexOf("/");
  if(point>0){
    url = url.substring(0,point+1);
  }
  url = url+$("#id").val()+".ha";
  $("#ipt_call_url").val(url);
  return url;
}

function doCallUrl(){
  var url = $("#ipt_call_url").val();
  if(url.trim()==""){
    url = getCallUrl();
  }
  window.open(url);
}

function geCrontabTime(){
  var res = getJson("*{/N100096.ha}","id="+$("#script_main_info").find("#id").val());
  $("#crontab_last_time").val(res.last_time);
  $("#crontab_next_time").val(res.next_time);
}

//检查页面url中是否有脚本主键id值，如果有，默认显示
function showLoadScript(){
  var scriptId = getRequest("id");
  if(!scriptId){
    //默认打开菜单
    $("#float-menu-open").animate(
        {
            left: '-70px'
        }, 300, function(){
        $('#float-menu-area').delay(50).animate({
            left: '0px'
        },300);
    });
    return;
  }
  ml_close_menu();
  $("#source_info").html(getUrlValue("*{/editor/editor.htm}","path="+scriptId));
  $("#content").val(fixResContent($("#content").val()));
  createEditor();
  showForScriptInfo();
  showRouteScriptInfo();
  independentClassClick();
  $("#page_title").text($("#script_main_info").find("#id").val()+" "+$("#title").val());
}
showLoadScript();


function editorWrap(node){
  if(!editor){
    return;
  }
  node = $(node);
  var auto = false;
  if(node.attr("is_auto")=="1"){
    node.attr("is_auto","0");
  }else{
    auto = true;
    node.attr("is_auto","1");
  }
  editor.setOption("lineWrapping",auto);
}

function clearErrorFlag(){
  var id = $("#source_info").find("#id").val();
  if(!id || id==""){
    return;
  }
  var res = getJson("*{/N100140.ha}","id="+id);
  if(!res){
    return;
  }
  alert(res.msg);
}

function clearError(){
  var id = $("#source_info").find("#id").val();
  if(!id || id==""){
    return;
  }
  var res = getJson("*{/N100141.ha}","id="+id);
  if(!res){
    return;
  }
  alert(res.msg);
}
     
function clearRunErrorFlag(){
  var id = $("#source_info").find("#id").val();
  if(!id || id==""){
    return;
  }
  var res = getJson("*{/N100137.ha}","id="+id);
  if(!res){
    return;
  }
  alert(res.msg);
}

function clearRunError(){
  var id = $("#source_info").find("#id").val();
  if(!id || id==""){
    return;
  }
  var res = getJson("*{/N100139.ha}","id="+id);
  if(!res){
    return;
  }
  alert(res.msg);
}

function gotoScript(node){
  var scriptId = $(node).text();
  window.open("*{/editor/index.htm}&id="+scriptId);
}
</script>
<form id="source_form" action="*{/editor/source.htm}" method="POST" target="_blank"  style="display:none;">
    <textarea name="xml_string" id="xml_string" /></textarea>
</form>
</body>
</html>